<template>
  <div class="warpper-box">
    <div class="inner_box">
      <el-form :inline="true" size="small" :model="formInline" ref="formInline">
        <el-form-item label="入库时间" prop="time">
          <el-date-picker
            v-model="formInline.time"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="loadList(true)"
            >搜索</el-button
          >
          <el-button
            type="primary"
            icon="el-icon-setting"
            @click="reset('formInline')"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <supplier-common-list
        ref="createSupplier"
        :tableData="tables.tableData"
        :tableLabel="tables.tableLabel"
        :models="tables"
        @on-search-click="loadList"
        @on-edit-click="editInfoClick"
        @on-store-detail-click="onStoreDetailClick"
      />
    </div>
    <myEditStore
      ref="createMyEditStore"
      @onOk="loadList"
      title="修改入库资料"
    />
    <infoStore ref="createInfoStore" />
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import { getSupplierStorePage, supplierStoreApply } from "@/api/supplier_api";
import { MY_STORE_LABEL } from "@/views/supplier/supplierModel/config";
import supplierCommonList from "@/views/supplier/supplierModel/supplier_common_list.vue";
import myEditStore from "@/views/supplier/supplierModel/my_edit_store.vue";
import infoStore from "@/views/supplier/supplierModel/info_store.vue";
export default {
  components: {
    supplierCommonList,
    myEditStore,
    infoStore
  },
  data() {
    return {
      formInline: {
        name: "",
        contactPerson: "",
        contactPhone: "",
        statusFlag: "",
        email: "",
        applyCategoryId: "",
        time: [],
        times: []
      },
      tables: {
        total: 0,
        isStore: true,
        tableData: [],
        tableLabel: MY_STORE_LABEL
      },
      models: {
        pageNum: 1,
        pageSize: 10
      }
    };
  },
  computed: {
    ...mapGetters(["findType", "permission_user"])
  },
  mounted() {
    this.loadList(true);
  },
  methods: {
    async loadList(formData) {
      let param = {};
      if (typeof formData == "boolean") {
        this.models.pageNum = 1;
        this.models.pageSize = 10;
        if (this.$refs.createSupplier) {
          this.$refs.createSupplier.clearSelected();
        }
      }
      if (typeof formData == "object") {
        this.models.pageNum = formData.pageNum;
        this.models.pageSize = formData.pageSize;
        if (this.$refs.createSupplier) {
          this.$refs.createSupplier.clearSelected();
        }
      }
      if (this.formInline.time && this.formInline.time.length) {
        param.storeStartTime = this.formInline.time[0];
        param.storeEndTime = this.formInline.time[1];
      }

      // param.applyCategoryId = this.formInline.applyCategoryId;
      param.pageNum = this.models.pageNum;
      param.pageSize = this.models.pageSize;
      param.storeType = "1";
     param.supplierId = this.permission_user.purchaseSupplier?.id;
      if (!param.supplierId) {
        this.tables.tableData = []
        this.tables.total = 0
        return;
      }
      const { code, data } = await getSupplierStorePage(param);
      if (code == 200) {
        //  0 待审核  1 通过  2驳回
        data.list.forEach(v => {
          v.storeSupplierId = v.id;
          v.id = v.applyId;
          if (v.newUpdateId) {
            if (v.newUpdateStatus == "1" || v.newUpdateStatus == "2") {
              v.edit = true;
            } else {
              v.edit = false;
            }
          } else if (v.storeStatus == "1" || v.storeStatus == "2") {
            v.edit = true;
          }
          // if (v.newUpdateId && v.newUpdateStatus && v.storeStatus !== "1") {
          //   v.edit = false;
          //   v.storeStatus = "0";
          // } else {
          //   if (v.storeStatus == "1" || v.storeStatus == "2") {
          //     v.edit = true;
          //   }
          // }
        });
        this.tables.tableData = data.list;
        this.tables.total = data.total;
      }
    },
    reset(formName) {
      this.$refs[formName].resetFields();
      this.formInline.applyCategoryId = "";
      this.loadList(true);
    },
    onStoreDetailClick(row) {
      this.$refs.createInfoStore.openDetail(row);
    },
    editInfoClick(row) {
      this.$refs.createMyEditStore.openStoreForm(row);
    }
  }
};
</script>
<style scoped>
.pass-box {
  display: flex;
}
.pass-tree {
  border: 1px solid rgb(235, 238, 244);
  width: 20%;
  margin-right: 20px;
}
.tree-prop {
  height: calc(100vh - 208px);
  overflow: auto;
  padding: 10px;
}
.pass-list {
  flex: 1;
}
.psm-duo {
  margin-bottom: 10px;
}
</style>
